using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter30
{
	/// <summary>
	/// Example08: Magnetic Flux Through a Rectangular Loop
	/// A rectangular loop of width a and length b is located 
	/// near a long wire carrying a current I (Fig. 30.22). 
	/// The distance between the wire and the closet side of 
	/// the loop is c. The wire is parallel to the long side 
	/// of the loop. Find the total magnetic flux through the 
	/// loop due to the current in the wire.
	/// </summary>
	public class Example08
	{
		public Example08()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Vector.Field vf = new L.Vector.Field(bfield);
			L.MagneticField B = new L.MagneticField();
            B.VectorField = vf;

			L.Surface.Parameterization paraToPosition
				= new L.Surface.Parameterization(func);
			L.Surface S = new L.Surface();
            S.ParameterToPosition = paraToPosition;
			S.Parameter1StartValue = 1.0;
			S.Parameter1EndValue = 2.0;
			S.Parameter2StartValue = 0.0;
			S.Parameter2EndValue = 3.0;
		
			L.Time t = new L.Time();
			L.MagneticFlux Phi = new L.MagneticFlux(B,S,t);
			result+=Convert.ToString(Phi.Wb)+"  +/-   "+
				Convert.ToString(Phi.StandardDeviation)+"\r\n";
			result+=Convert.ToString(3.0/2.0/Math.PI
				*Math.Log(1.0+1.0/1.0))+"\r\n";
		}
		private L.Vector bfield(L.Position r, L.Time t)
		{
			L.Vector v = new L.Vector();
			v.X = 0.0;
			v.Y = 0.0;
			v.Z = -1.0/2.0/Math.PI/r.X;
			return v;
		}
		private L.Position func(double p1, double p2)
		{
            L.Position x = new L.Position();
            x.X = p1;
            x.Y = p2;
            x.Z = 0.0;
     		return x;
		}
	}
}
